package tableViewBinding;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;

public class TableWithDetailsController {
	private @FXML
	TableView<Person> tableView;
	private @FXML
	DetailsPaneController detailsPaneController;

	public void initialize() {
		final ObservableList<Person> data = FXCollections.observableArrayList(new Person(1, "Joe", "Pesci"), new Person(2, "Audrey", "Hepburn"), new Person(3,
				"Gregory", "Peck"), new Person(4, "Cary", "Grant"), new Person(5, "Robert", "De Niro"));

		tableView.setItems(data);

		TableColumn<Person, Integer> idColumn = new TableColumn<Person, Integer>();
		idColumn.setCellValueFactory(new PropertyValueFactory<Person, Integer>("id"));
		TableColumn<Person, String> firstNameColumn = new TableColumn<Person, String>();
		firstNameColumn.setCellValueFactory(new PropertyValueFactory<Person, String>("firstName"));
		TableColumn<Person, String> lastNameColumn = new TableColumn<Person, String>();
		lastNameColumn.setCellValueFactory(new PropertyValueFactory<Person, String>("lastName"));

		tableView.getColumns().addAll(idColumn, firstNameColumn, lastNameColumn);

		detailsPaneController.personProperty().bind(tableView.getSelectionModel().selectedItemProperty());
	}
}